<!--  -->
<template>
  <div class="qq-music-new">
    <h1>新 歌 首 发</h1>
    <ul>
      <li v-for="item in newListName" :key="item.id">
        <a
          href="javascript:;"
          @click="getnewlist(item.type)"
          :class="[{ green: isGreen === item.type }]"
          >{{ item.name }}</a
        >
      </li>
    </ul>
    <div class="new-list">
      <div class="list" v-for="item in newList" :key="item.album.id">
        <div class="list-box">
          <div class="imgbox">
            <div class="mask">
              <img
                src="https://y.gtimg.cn/mediastyle/yqq/img/cover_play@2x.png?max_age=2592000&v=88abebcbc1242dbbbbc836cc3e04a006&v=88abebcbc1242dbbbbc836cc3e04a006&v=10e4305a2558d496548955434eaa30d9"
                alt=""
              />
            </div>
            <img :src="item.album.blurPicUrl" alt="" />
          </div>
          <div>
            <p>{{ item.name }}</p>
            <span>{{ item.artists[0].name }}</span>
            <div class="time">{{ getTime(item.duration) }}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';

export default {
  //import引入的组件需要注入到对象中才能使用
  components: {},
  data() {
    //这里存放数据
    return {
      isGreen: 0,
      type: 0,
      newList: [],
      newListName: [
        { name: "全部", id: 1, type: 0 },
        { name: "华语", id: 2, type: 7 },
        { name: "欧美", id: 3, type: 96 },
        { name: "日本", id: 4, type: 8 },
        { name: "韩国", id: 5, type: 16 },
      ],
    };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    getnew: async function () {
      let res = await this.$http.get("/top/song", {
        params: {
          type: this.type,
        },
      });
      this.newList = res.data.data.splice(0, 9);
      // console.log(res);
      // console.log(this.newList);
    },
    getnewlist: function (type) {
      this.isGreen = type;
      this.type = type;
      this.getnew();
    },
    getTime: function (time) {
      let minutes = parseInt(time / 60000);
      let seconds = parseInt(time / 1000) % 60;
      if (minutes < 10) {
        minutes = "0" + minutes;
      }
      if (seconds < 10) {
        seconds = "0" + seconds;
      }
      return minutes + ":" + seconds;
    },
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
    this.getnew();
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style lang='less' scoped>
.qq-music-new {
  background: -webkit-linear-gradient(top, #eee, white);
  margin: 0 auto;
  text-align: center;
  overflow: hidden;
  margin-bottom: 40px;
  h1 {
    margin: 20px 0;
    font-weight: 500;
  }

  ul {
    display: flex;
    width: 600px;
    margin: 0 auto;
    justify-content: space-between;
    margin-bottom: 20px;
    li {
      list-style: none;

      a {
        text-decoration: none;
        color: #000;
      }
      a:hover {
        color: #31c27c;
      }
      .green {
        color: #31c27c;
      }
    }
  }

  .new-list {
    display: flex;
    width: 1200px;
    margin: 0 auto;
    flex-wrap: wrap;

    .list {
      .list-box {
        position: relative;
        display: flex;
        width: 380px;
        margin: 0 10px;
        padding: 10px 0;
        border-bottom: 1px solid #f2f2f2;
        margin-top: -1px;
        .imgbox {
          width: 80px;
          height: 80px;
          position: relative;
          overflow: hidden;
          cursor: pointer;
          .mask {
            width: 80px;
            height: 80px;
            opacity: 0;
            position: absolute;
            transition: all 0.5s linear;
            background: rgba(30, 30, 30, 0.2);
            img {
              position: absolute;
              top: 24px;
              left: 24px;
              width: 30px;
              height: 30px;
            }
          }
          img {
            width: 80px;
            height: 80px;
            transition: all 0.5s linear;
            margin-bottom: 10px;
          }
        }
        .imgbox:hover {
          .mask {
            opacity: 1;
            z-index: 999;
          }
          img {
            transform: scale(1.1);
          }
        }
        // img {
        //   width: 80px;
        //   height: 80px;
        // }

        p {
          text-align: left;
          margin-top: 16px;
          margin-left: 10px;
          font-size: 14px;
          cursor: pointer;
        }
        p:hover {
          color: #31c27c;
        }
        span {
          color: #999;
          display: block;
          text-align: left;
          margin-left: 10px;
          font-size: 14px;
          margin-top: 4px;
          cursor: pointer;
        }
        span:hover {
          color: #31c27c;
        }
        .time {
          top: 35px;
          right: 0;
          position: absolute;
          font-size: 14px;
          color: #999;
        }
      }
    }
  }
}
</style>